import random


def choose_balls(cnt, up, balls, label, source):
    n = len(balls)
    while n <= cnt:
        try:
            el = int(input('Input the #%d %s ball: ' % (n + 1, label)))
        except ValueError:
            print('Only 1-%d is available!' % up)
            continue
        if not (el in source):
            print('Only 1-%d is available!' % up)
            continue
        balls.add(el)


redBalls = list(range(1, 33 + 1))
blueBalls = list(range(1, 16 + 1))
userArea = []
comments = []

while True:
    reds = set()
    blues = set()
    doubleBalls = ['Red', None, 'Blue', None, 'multiple', None]

    ch = input('Auto choice or not? (y/n/(q)uit/(p)ay/(c)omments)').strip().lower()
    if 'y' == ch:
        reds.extend(random.sample(redBalls, k=6))
        blues = [random.choice(blueBalls)]
    elif 'q' == ch:  # quit
        print('Bye!')
        break
    elif 'p' == ch:  # pay
        total = 0
        for single in userArea:
            total += single[5]
            print(single)
            total *= 2
        print('You need to pay %d yuan.' % total)
        comment = input('Any comment?').strip()
        if len(comment) > 0:
            comments.append(comment)
        continue
    elif 'c' == ch:  # check comments
        print('Comments:')
        for comment in comments:
            print('\t>', comment)
        continue
    else:
        choose_balls(6, 33, reds, 'red', redBalls)
        choose_balls(1, 16, blues, 'blue', blueBalls)

    reds.sort()
    doubleBalls[1] = reds
    doubleBalls[3] = blues

    print('Your choices:', doubleBalls)
    mul = int(input('How many?'))
    doubleBalls[5] = mul

    print('Your choices:', doubleBalls)
    userArea.append(doubleBalls)
    for single in userArea:
        print(single)
